﻿using System.Windows;
using System.Reflection;
using System.Windows.Controls;

namespace Builderator.Firefly.Controls
{
    /// <summary>
    /// Interaction logic for CheckBoxControl.xaml
    /// </summary>
    public partial class CheckBoxControl : UserControl, IProperty
    {
        public static DependencyProperty BoolProperty = DependencyProperty.Register("Update", typeof(bool), typeof(CheckBoxControl));

        public new event PropertyChanged OnPropertyChanged;

        public PropertyInfo Property
        {
            get;
            set;
        }

        public bool Checked 
        {
            get
            {
                return bool.Parse((string)this.GetValue(BoolProperty));
            }
            set
            {
                this.SetValue(BoolProperty, value);

                this.checkBox.IsChecked = value;

                if (this.OnPropertyChanged != null)
                    this.OnPropertyChanged(this.Property, value);
            }
        }

        private CheckBoxControl()
        {
            InitializeComponent();
        }

        public CheckBoxControl(PropertyInfo property)
            : this()
        {
            this.Property = property;
        }

        private void checkBox_Checked(object sender, RoutedEventArgs e)
        {
            this.Checked = true;
        }

        private void checkBox_Unchecked(object sender, RoutedEventArgs e)
        {
            this.Checked = false;
        }
    }
}
